﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Event.NCL;
using CPPEI.Coolzon.Service.Contract;
using CPPEI.Coolzon.UI.Data;
using Sunboxsoft.ChanceData.ServiceProxy.MainServiceRef;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.Views.EventProxies
{
    public class RespCloseSceneHandler : BaseResponseHandler<RespCloseSceneData>
    {
        protected override void OnHandle(RemoteEventProxy remoteEventProxy, Response response, RespCloseSceneData responseData)
        {
            if (UIContext.Current.AppType.ToUpper() == "DISPLAYAPP" && !UIContext.Current.IsUnderControl)
            {
                // 展示端且不在控制模式下，不处理来自服务器的切换事件
                return;
            }

            SwitchMode switchMode = SwitchMode.Replace;
            if (string.Equals("POP", responseData.Mode, StringComparison.CurrentCultureIgnoreCase))
            {
                switchMode = SwitchMode.Pop;
            }
            Common.Logger.DebugToTag("RespOpenSceneHandler", "接收事件-关闭 scene:{0},mode:{1}", responseData.SceneName, responseData.Mode);
            remoteEventProxy.RenderView.OnBack(switchMode, responseData.FrameName, "", responseData.SceneName);

            Coolzon.Event.NCL.NCLCloseSceneEvent @event = new Coolzon.Event.NCL.NCLCloseSceneEvent(switchMode, responseData.FrameName, responseData.SceneName);
            @event.State = NCLEventState.Finished;
            NCLEventBus.PublishAsync(@event);
        }
    }
}
